package com.dq.Controller;

import com.dq.Pojo.Classtable;
import com.dq.Pojo.Result;
import com.dq.Service.ClassService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/class")
public class ClassController {
    @Autowired
    private ClassService classService;

    @PostMapping("/addclass")
    public Result addclass(@RequestBody Classtable classtable){
        classService.addclass(classtable);
        return Result.success();
    }
    @GetMapping("/findAll")
    public Result<PageInfo<Classtable>> findAll(@RequestParam Integer pageNum,
                                      @RequestParam Integer pageSize,
                                      @RequestParam String classname){
        PageInfo<Classtable> classtablePageInfo=classService.findAll(pageNum,pageSize,classname);
        return  Result.success(classtablePageInfo);
    }
    @DeleteMapping("/delete")
    public Result delete(@RequestParam Integer id){
        classService.delete(id);
        return Result.success();
    }
    //id获取信息
    @GetMapping("/getByid")
    public Result<Classtable> getByid(@RequestParam Integer id){
        Classtable classtable= classService.getByid(id);
        return Result.success(classtable);

    }
    //修改
    @PutMapping("/update")
    public Result update(@RequestBody Classtable classtable){
        classService.update(classtable);
        return Result.success(classtable);
    }
    @GetMapping("/find")
    public Result find(){
        List<Classtable> classtablelist =classService.find();
        return Result.success(classtablelist);
    }


}
